package com.sc.nft.service.impl;

import com.sc.nft.dao.MallMemberEquityTargetDao;
import com.sc.nft.dao.MallMemberEquityUseRecordDao;
import com.sc.nft.entity.MallMemberEquityTarget;
import com.sc.nft.entity.MallMemberEquityUseRecord;
import com.sc.nft.service.MallMemberEquityUseRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Objects;

/**
 * @author JYT
 * @create 2024/4/8 17:28
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class MallMemberEquityUseRecordServiceImpl implements MallMemberEquityUseRecordService {
    private final MallMemberEquityUseRecordDao mallMemberEquityUseRecordDao;
    private final MallMemberEquityTargetDao mallMemberEquityTargetDao;

    @Override
    public boolean create(long mallMemberEquityTargetId, Long userId, Long orderId) {
        MallMemberEquityTarget memberEquityTarget = mallMemberEquityTargetDao.getById(mallMemberEquityTargetId);
        if (Objects.isNull(memberEquityTarget)) return false;
        MallMemberEquityUseRecord mallMemberEquityUseRecord = new MallMemberEquityUseRecord();
        mallMemberEquityUseRecord.setMallOrderId(orderId);
        mallMemberEquityUseRecord.setUserId(userId);
        mallMemberEquityUseRecord.setMallMemberEquityId(memberEquityTarget.getMallMemberEquityId());
        mallMemberEquityUseRecord.setMallMemberEquityTargetId(mallMemberEquityTargetId);
        return mallMemberEquityUseRecordDao.save(mallMemberEquityUseRecord);
    }

    @Override
    public MallMemberEquityUseRecord getByOrderId(Long orderId) {
        return mallMemberEquityUseRecordDao.getByOrderId(orderId);
    }

    @Override
    public boolean deleteById(Long id) {
        return mallMemberEquityUseRecordDao.deleteById(id);
    }

    /**
     * 获取用户通过会员权益下单列表
     *
     * @param memberId
     * @param mallMemberEquityTemplateId
     * @param userId
     * @return
     */
    @Override
    public List<MallMemberEquityUseRecord> getByMallMemberEquityId(Long memberId, Long mallMemberEquityTemplateId, Long userId, Date startTime, Date endTime) {
        return mallMemberEquityUseRecordDao.getByMallMemberEquityId(memberId, mallMemberEquityTemplateId, userId,startTime,endTime);
    }
}
